package net.tngou.boot.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.tngou.boot.jdbc.OrderType;
import net.tngou.boot.jdbc.PageUtil;
import net.tngou.boot.pojo.POJO;
import net.tngou.boot.util.SpringBeansUtil;






/**
 * 基础Service
 * @author tngou@tngou.net
 *
 */
@Service
public class BaseService {
	@Autowired
	protected SpringBeansUtil beans;

	/**
	 * 列表
	 * @param pojoClass
	 * @return
	 */
	public List<?> getList(Class<? extends POJO> pojoClass) {		
		List<?> list = null;	
		POJO pojo = beans.getBean(pojoClass);
		list=pojo.list();
		return list;	
	}
	
    public List<?> getList(String type,OrderType orderType,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = null;
		list = pojo.list(type,orderType);		
 	    return list;		
	}
    public List<?> getList(String filter,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(filter);		
 	    return list;
			
	} 
    public List<?> getList(Map<String, Object> map,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(map);		
 	    return list;
			
	} 
    public List<?> getList(Map<String, Object> map,int page,int size,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(map,page,size);		
 	    return list;
			
	}
    public List<?> getList(Map<String, Object> map,String type,OrderType orderType,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(map,type,orderType);		
 	    return list;
			
	} 
    public List<?> getList(Map<String, Object> map,String type,OrderType orderType,int page,int size,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(map,type,orderType,page,size);		
 	    return list;
			
	} 
    public List<?> getList(String filter,String type,OrderType orderType,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(filter,type,orderType);		
 	    return list;
			
	}  
    public List<?> getList(int page,int size,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list = pojo.list(page, size);		
 	    return list;		
	}
    public List<? > getList(int page,int size,String type,OrderType order,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);	   
		List<?> list = pojo.list(page, size, type, order);		
 	    return list;		
	}
    
  
    
    public List<?> getList(int page,int size,String filter,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
       List<?> list =  pojo.list(filter, page, size);
 	   return list;
			
	}
    
    public List<?> getList(int page,int size,String filter,String type,OrderType orderType,Class<? extends POJO> beanClass) {
    	POJO pojo = beans.getBean(beanClass);
    	List<?> list =  pojo.list(filter, page, size, type, orderType);		
 	    return list;		
	}

	/**
	 * 取得page
	 * @param page
	 * @param size
	 * @param pojo
	 * @return
	 */
	public PageUtil getPage(int page,int size,Class<? extends POJO> beanClass) {
		   POJO pojo = beans.getBean(beanClass);
		   PageUtil pageUtil=new PageUtil(pojo.list(page, size),page,size,pojo.totalCount());		
		   return pageUtil;		
		}
		
		public PageUtil getPage(int page,int size,String type,OrderType order,Class<? extends POJO> beanClass) {
			 POJO pojo = beans.getBean(beanClass);
			 PageUtil pageUtil=new PageUtil(pojo.list(page, size, type, order),page,size,pojo.totalCount());		
			 return pageUtil;
			
		}
		
		public PageUtil getPage(int page,int size,String filter,Class<? extends POJO> beanClass) {
			POJO pojo = beans.getBean(beanClass);
			PageUtil pageUtil=new PageUtil(pojo.list(filter, page, size),page,size,pojo.totalCount(filter));	
			return pageUtil;	
		}
       public PageUtil getPage(int page,int size,String filter,String type,OrderType order,Class<? extends POJO> beanClass) {
    	   POJO pojo = beans.getBean(beanClass);
		   PageUtil pageUtil=new PageUtil(pojo.list(filter, page, size,type, order),page,size,pojo.totalCount(filter));		
		   return pageUtil;
			
		}

}
